package com.mostromas.ess.product.controller;

import com.mostromas.ess.entities.ProductColor;
import com.mostromas.ess.entities.SecurityCategory;
import com.mostromas.ess.product.service.ISecurityCategoryService;
import com.mostromas.ess.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 安全类别表-前端控制器
 */
@Api(value = "安全类别管理接口",description = "安全类别管理接口，提供安全类别的增、删、改、查")
@RestController //所有方法都会返回json字符串进行相应
@RequestMapping("/security_category")
public class SecurityCategoryController {

    @Autowired
    private ISecurityCategoryService securityCategoryService;

    @PreAuthorize(("hasAuthority('security_category:search')"))
    @ApiOperation("获取所有的安全类别信息接口")
    @GetMapping("/list")
    public Result list(){
        return Result.ok(securityCategoryService.list());
    }

    @PreAuthorize(("hasAuthority('security_category:search')"))
    @ApiOperation("查询安全类别详情接口")
    @ApiImplicitParam(name = "id",value = "安全类别ID",required = true)
    @GetMapping("/{id}")
    public Result view(@PathVariable("id") String id){
        SecurityCategory securityCategory = securityCategoryService.getById(id);
        return Result.ok(securityCategory);
    }

    @PreAuthorize(("hasAuthority('security_category:edit')"))
    @ApiOperation("修改安全类别信息接口")
    @PutMapping
    public Result update(@RequestBody SecurityCategory securityCategory){
        securityCategoryService.updateById(securityCategory);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('security_category:add')"))
    @ApiOperation("新增安全类别信息接口")
    @PostMapping
    public Result save(@RequestBody SecurityCategory securityCategory){
        securityCategoryService.save(securityCategory);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('security_category:delete')"))
    @ApiOperation("删除安全类别信息接口")
    @ApiImplicitParam(name = "id",value = "安全类别ID",required = true)
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id){
        securityCategoryService.removeById(id);
        return Result.ok();
    }
}
